home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / rpg / crossfir.92 / crossfir / crossfire-0.92.5 / common / init.c < prev    next >
C/C++ Source or Header  |  1996-07-24  |  5KB  |  199 lines

  1. /*
  2.  * static char *rcsid_init_c =
  3.  *   "$Id: init.c,v 1.19 1994/11/09 02:59:20 master Exp $";
  4.  */
  5.  
  6. /*
  7.     CrossFire, A Multiplayer game for X-windows
  8.  
  9.     Copyright (C) 1992 Frank Tore Johansen
  10.  
  11.     This program is free software; you can redistribute it and/or modify
  12.     it under the terms of the GNU General Public License as published by
  13.     the Free Software Foundation; either version 2 of the License, or
  14.     (at your option) any later version.
  15.  
  16.     This program is distributed in the hope that it will be useful,
  17.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.     GNU General Public License for more details.
  20.  
  21.     You should have received a copy of the GNU General Public License
  22.     along with this program; if not, write to the Free Software
  23.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  
  25.     The author can be reached via e-mail to frankj@ifi.uio.no.
  26. */
  27.  
  28. #define EXTERN
  29. #include <global.h>
  30. #include <object.h>
  31.  
  32. /*
  33.  * It is vital that init_library() is called by any functions
  34.  * using this library.
  35.  * If you want to lessen the size of the program using the library,
  36.  * you can replace the call to init_library() with init_globals() and
  37.  * init_function_pointers().  Good idea to also call init_vars and
  38.  * init_hash_table if you are doing any object loading.
  39.  */
  40.  
  41. void init_library() {
  42.   init_globals();
  43.   init_function_pointers();
  44.   init_hash_table();
  45.   init_objects();
  46.   init_vars();
  47.   init_block();
  48.   ReadBmapNames ();
  49.   init_archetypes();    /* Reads all archetypes from file */
  50.   init_dynamic ();
  51. }
  52.  
  53. /*
  54.  * Initialises all global variables.
  55.  * Might use environment-variables as default for some of them.
  56.  */
  57.  
  58. void init_globals() {
  59.   logfile = stderr;
  60.   exiting = 0;
  61. #ifndef SECURE
  62.   LibDir=getenv("CROSSFIRE_LIBDIR");
  63.   if (!LibDir)
  64. #endif
  65.     LibDir=LIBDIR;
  66. #ifndef SECURE
  67.   FontDir=getenv("CROSSFIRE_FONTDIR");
  68.   if (!FontDir)
  69. #endif
  70.     FontDir=FONTDIR;
  71. #ifndef SECURE
  72.   PlayerDir=getenv("CROSSFIRE_PLAYERDIR");
  73.   if (!PlayerDir)
  74. #endif
  75.     PlayerDir=PLAYERDIR;
  76. #ifndef SECURE
  77.   MapDir=getenv("CROSSFIRE_MAPDIR");
  78.   if (!MapDir)
  79. #endif
  80.     MapDir=MAPDIR;
  81. #ifndef SECURE
  82.   ArcheTypes=getenv("CROSSFIRE_ARCHETYPES");
  83.   if (!ArcheTypes)
  84. #endif
  85.     ArcheTypes=ARCHETYPES;
  86. #ifndef SECURE
  87.   Treasures=getenv("CROSSFIRE_TREASURES");
  88.   if (!Treasures)
  89. #endif
  90.     Treasures=TREASURES;
  91. #ifdef UNIQUE_ITEMS
  92. #ifndef SECURE
  93.   ItemsDir=getenv("CROSSFIRE_ITEMSDIR");
  94.   if (!ItemsDir)
  95. #endif
  96.     ItemsDir=ITEMS_DIR;
  97. #endif
  98.   delete_last_file=0;
  99.   first_player=NULL;
  100.   first_friendly_object=NULL;
  101.   first_map=NULL;
  102.   first_treasurelist=NULL;
  103.   first_artifactlist=NULL;
  104.   chrfont=NULL;
  105.   first_archetype=NULL;
  106.   warn_archetypes=0;
  107.   first_map=NULL;
  108.   write_state=0;
  109.   write_pos=0;
  110.   write_d=0;
  111.   button_flag=0;
  112.   last_bard=0;
  113.   fix_walls=0;
  114.   default_split_window=0;
  115.   dump_monsters=0;
  116.   monsters = 1;
  117.   generators = 1;
  118.   hidden = 0;
  119.   others = 1;
  120.   last_micro = 0;
  121.   nroftreasures = 0;
  122.   nrofartifacts = 0;
  123.   nrofallowedstr=0;
  124.   ring_arch = NULL;
  125.   amulet_arch = NULL;
  126.   staff_arch = NULL;
  127.   undead_name = add_string("undead");
  128.   use_pixmaps = 0;
  129.   name = strdup_local("crossfire");
  130.   server_mode = SERVER_OFF;
  131.   active_socket = (sockets *) NULL;
  132.   first_socket = (sockets *) NULL;
  133.   font_graphic = FONTNAME;
  134.   trying_emergency_save = 0;
  135.  
  136.   init_defaults();
  137. }
  138.  
  139. /*
  140.  * Sets up and initialises the linked list of free and used objects.
  141.  * Allocates a certain chunk of objects and puts them on the free list.
  142.  * Called by init_library();
  143.  */
  144.  
  145. void init_objects() {
  146.   int i;
  147. /* Initialize all objects: */
  148.   free_objects=objarray;
  149.   objects=NULL;
  150.   active_objects = NULL;
  151.   objarray[0].prev=NULL,
  152.   objarray[0].next= &objarray[1],
  153.   SET_FLAG(&objarray[0], FLAG_REMOVED);
  154.   SET_FLAG(&objarray[0], FLAG_FREED);
  155.   for(i=1;i<STARTMAX-1;i++) {
  156.     objarray[i].next= &objarray[i+1];
  157.     objarray[i].prev= &objarray[i-1];
  158.     SET_FLAG(&objarray[i], FLAG_REMOVED);
  159.     SET_FLAG(&objarray[i], FLAG_FREED);
  160.   }
  161.   objarray[STARTMAX-1].next=NULL;
  162.   objarray[STARTMAX-1].prev= &objarray[STARTMAX-2];
  163.   SET_FLAG(&objarray[STARTMAX-1], FLAG_REMOVED);
  164.   SET_FLAG(&objarray[STARTMAX-1], FLAG_FREED);
  165. }
  166.  
  167. /*
  168.  * Initialises global variables which can be changed by options.
  169.  * Called by init_library().
  170.  */
  171.  
  172. void init_defaults() {
  173.   fix_fontpath=1;
  174.   synchronize=1;
  175. #ifdef DEBUG
  176.   debug= llevDebug;
  177. #else
  178.   debug= llevError;
  179. #endif
  180.   no_color=0;
  181.   editor=0;
  182.   maplevel=0; /* What level the map we're editing has */
  183.   nroferrors=0;
  184. }
  185.  
  186.  
  187. void init_dynamic () {
  188.     archetype *at = first_archetype;
  189.     while (at) {
  190.     if (at->clone.type == MAP && EXIT_PATH (&at->clone)) {
  191.         strcpy (first_map_path, EXIT_PATH (&at->clone));
  192.         return;
  193.     }
  194.     at = at->next;
  195.     }
  196.     LOG(llevDebug,"You Need a archetype called 'map' and it have to contain start map\n");
  197.     exit (-1);
  198. }
  199.